package com.aokser.redisplugin.redis;

import com.aokser.redisplugin.exception.RedisPluginException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
import java.util.Set;


/**
 * 集群环境客户端接口实现 
 * @version 1.0
 * @author aokser@foxmail.com
 */
@Component
@Lazy(true)
public class RedisPluginClusterClient extends AbstractRedisPluginClient {


    @Autowired
    private JedisClusterClient jedisClusterClient;

    @Override
    public void subscribe(RedisPluginSubscribe redisPluginSubscribe, String channel) throws
            RedisPluginException {
        try {
            jedisClusterClient.subscribe(redisPluginSubscribe, channel);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }


    @Override
    public void publish(String channel, String message) throws
            RedisPluginException {
        try {
            jedisClusterClient.publish(channel, message);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public String get(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.get(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }
    
    @Override
	public int getNodesSize() {
    	return jedisClusterClient.getNodesSize();
	}

    @Override
    public byte[] get(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.get(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void set(String key, String value) throws RedisPluginException {
        try {
            jedisClusterClient.set(key, value);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void set(byte[] key, byte[] value) throws RedisPluginException {
        try {
            jedisClusterClient.set(key, value);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void del(String key) throws RedisPluginException {
        try {
            jedisClusterClient.del(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void del(byte[] key) throws RedisPluginException {
        try {
            jedisClusterClient.del(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void lpush(String key, String value) throws RedisPluginException {
        try {
            jedisClusterClient.lpush(key, value);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void lpush(byte[] key, byte[] value) throws RedisPluginException {
        try {
            jedisClusterClient.lpush(key, value);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void rpush(String key, String value) throws RedisPluginException {
        try {
            jedisClusterClient.rpush(key, value);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public String lpop(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.lpop(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public byte[] lpop(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.lpop(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public String rpop(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.rpop(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public byte[] rpop(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.rpop(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public Long llen(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.llen(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public Long llen(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.llen(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public List<String> lrange(String key, long start, long end)
            throws RedisPluginException {
        try {
            return jedisClusterClient.lrange(key, start, end);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public List<byte[]> lrange(byte[] key, long start, long end)
            throws RedisPluginException {
        try {
            return jedisClusterClient.lrange(key, start, end);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void sadd(String key, String... value) throws RedisPluginException {
        try {
            jedisClusterClient.sadd(key, value);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void sadd(byte[] key, byte[]... value) throws RedisPluginException {
        try {
            jedisClusterClient.sadd(key, value);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void srem(String key) throws RedisPluginException {
        try {
            jedisClusterClient.srem(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void srem(byte[] key) throws RedisPluginException {
        try {
            jedisClusterClient.srem(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public long scard(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.scard(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public long scard(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.scard(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public Set<String> smembers(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.smembers(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public Set<byte[]> smembers(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.smembers(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void hset(String key, String field, String value)
            throws RedisPluginException {
        try {
            jedisClusterClient.hset(key, field, value);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public void hset(byte[] key, byte[] field, byte[] value)
            throws RedisPluginException {
        try {
            jedisClusterClient.hset(key, field, value);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public String hget(String key, String field) throws RedisPluginException {
        try {
            return jedisClusterClient.hget(key, field);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public byte[] hget(byte[] key, byte[] field) throws RedisPluginException {
        try {
            return jedisClusterClient.hget(key, field);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public List<String> hvals(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.hvals(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public Collection<byte[]> hvals(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.hvals(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public Set<String> hkeys(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.hkeys(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public Set<byte[]> hkeys(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.hkeys(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public long hlen(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.hlen(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public long hlen(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.hlen(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public long hdel(String key, String field) throws RedisPluginException {
        try {
            return jedisClusterClient.hdel(key, field);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public long hdel(byte[] key, byte[] field) throws RedisPluginException {
        try {
            return jedisClusterClient.hdel(key, field);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public long incr(String key) throws RedisPluginException {
        try {
            return jedisClusterClient.incr(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public long incr(byte[] key) throws RedisPluginException {
        try {
            return jedisClusterClient.incr(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
    }

    @Override
    public Set<String> keys(String key) throws RedisPluginException {
        return jedisClusterClient.keys(key);
    }

    @Override
    public Set<byte[]> keys(byte[] key) throws RedisPluginException {
        return jedisClusterClient.keys(key);
    }

    @Override
	public String type(String key) {
		try {
            return jedisClusterClient.type(key);
        } catch (Exception e) {
            throw new RedisPluginException(e);
        }
	}
}
